<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="../../static/css/bootstrap.min.css" rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}">
    <!-- Custom styles for this template -->
    <link href="../../static/css/dashboard.css" rel="stylesheet" th:href="@{/static/css/dashboard.css}">
</head>
<body>
<!--顶部导航栏-->
<div th:replace="~{student/common::topbar}"></div>
<div class="container-fluid">
    <div class="row">
        <!--侧边栏 组件化-->
        <div th:replace="~{student/common::sidebar(active='homePage.html')}"></div>
        <main class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4" role="main">
            <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
                <h1 class="h3">宿舍信息</h1>
                <div class="btn-toolbar mb-2 mb-md-0">
                    <div class="btn-group mr-2">
                        <button class="btn btn-sm btn-outline-secondary" id="btn-selfInfo">个人信息</button>
                        <button class="btn btn-sm btn-outline-secondary" id="btn-free">申请走读</button>
                        <button class="btn btn-sm btn-outline-secondary" id="btn-dormChange">申请换寝</button>
                    </div>
                    <div class="btn-group mr-2">
                        <button class="btn btn-primary btn-sm btn-outline-secondary" id="btn-admin">管理员</button>
                        <button class="btn btn-sm btn-outline-secondary" id="btn-student">重新登陆</button>
                    </div>
                </div>
            </div>
            <div th:switch="${dormId}">
                <div class="table-responsive" th:case="true">
                    <table class="table table-striped table-hover table-bordered table-sm">
                        <thead>
                        <tr>
                            <th>学号</th>
                            <th>姓名</th>
                            <th>性别</th>
                            <th>寝室门牌</th>
                            <th>寝室类型</th>
                            <th>床位</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <th th:text="${dorm.getSno()}"></th>
                            <th th:text="${dorm.getSname()}"></th>
                            <th th:text="${dorm.getDorm_gender()}"></th>
                            <th th:text="${dorm.getDormPlace()}"></th>
                            <th th:text="${dorm.getDorm_number()+'人间'}"></th>
                            <th th:text="${dorm.getBed_id()+'号床'}"></th>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div th:case="false">
                    <h1>你未住校!</h1>
                </div>
            </div>

        </main>
    </div>
</div>

<script src="../../static/js/jquery-3.6.0.js" th:src="@{/static/js/jquery-3.6.0.js}"></script>
<script src="../../static/js/jquery-session.js" th:src="@{/static/js/jquery-session.js}"></script>
<script src="../../static/js/bootstrap.min.js" th:src="@{/static/js/bootstrap.min.js}" type="text/javascript"></script>
<script src="../../static/js/btn.js" th:src="@{/static/js/btn.js}"></script>
<script>
    let sno = [[${session.student.getSno()}]];
    //个人信息
    let btnSelfInfo = $('#btn-selfInfo');
    //走读
    let btnFree = $('#btn-free');
    //换寝室
    let btnDormChange = $('#btn-dormChange');
    $.get({
        url: "/student/ajax/judgeStuDorm",
        data: {"sno": sno},
        success: function (result) {
            if (result === null) {
                btnSelfInfo.show();
                btnFree.hide();
                btnDormChange.hide();
            } else {
                if (result.sign === 0) {
                    btnSelfInfo.show();
                    btnFree.show();
                    btnDormChange.show();
                }
                //申请走读
                else if (result.sign === 1) {
                    btnSelfInfo.show();
                    btnFree.show();
                    btnDormChange.hide();
                }
                //换寝
                else if (result.sign === 2) {
                    btnSelfInfo.show();
                    btnFree.hide();
                    btnDormChange.show();
                }
            }
        }
    })

</script>
</body>
</html>